<? 
function hide_picture_blog($picture_ID, $main)
{
	$sql2 = "UPDATE `blog` SET `main_image_ID` = NULL WHERE `ID` = $main";
	mysql_query($sql2) or die("Cannot hide picture for entry<BR>" . $sql2);
	$sql="UPDATE `gallery` SET `active` = 0 WHERE `ID` = $picture_ID";
	mysql_query($sql) or die("Cannot hide picture<BR>" . $sql);
;
}
function show_picture_blog($picture_ID, $main)
{
	$sql2 = "UPDATE `blog` SET `main_image_ID` = $picture_ID WHERE `ID` = $main";
	mysql_query($sql2) or die("Cannot show picture for entry<BR>" . $sql2);
	$sql="UPDATE `gallery` SET `active` = 1 WHERE `ID` = $picture_ID";
	mysql_query($sql) or die("Cannot show picture<BR>" . $sql);
	
}

function print_image_for_entry($ID,$entry_ID)
{
	$sql = "SELECT * FROM `gallery` WHERE `ID` = $ID";
	$result = mysql_query($sql) or die("Cannot get picture for entry " . $sql);
	$retval = 0;
	for ($i=0;$i<mysql_num_rows($result);$i++)
	{
		$image_details = mysql_fetch_assoc($result); 
		echo "<A href='gallery_edit.php?realm=blog&picture=" . $image_details['ID'] . "'>Edit info for " . $image_details['title'] . "</A><BR>";
		echo "<A href='gallery_admin.php?realm=blog&action=hide&picture={$image_details['ID']}&main=$entry_ID'>Remove from entry</A><BR>";
				?>
		<BR>
		<img src="../images/<? echo $image_details['image_thumbnail'];?>" alt="<? echo $image_details['audio_description'];?>" />
		<BR>
		<?
		$retval=1;
		//echo "<a class='thumbnail' href='#thumb'><img src='images/{$image_details['image_thumbnail']}' width='8%' height='10%' border='0' /><span><img src='images/{$image_details['image']}' /><br />{$image_details['audio_description']}</span></a>";	
	}
	mysql_free_result($result);
	return $retval;
}

function print_all_entries()
{
	$sql="SELECT * FROM `blog` WHERE 1 ORDER BY `blog`.`ID` ASC";
	$result = mysql_query($sql) or die (mysql_error());
	for ($i=0;$i<mysql_num_rows($result);$i++)
	{
		$row = mysql_fetch_assoc($result); 
		$ID = $row['ID'];
		if (! empty($row['date']))
				$Date = format_and_extend_date($row['date']);
		else
				$Date = 'Planned';
		$Summary = $row['summary'];
		?>
		<H2 class="event_title"> <A href="gallery_upload.php?ID=<? echo $ID; ?>&oldpic=<?echo $row['main_image_ID'];?>">Upload image for entry:"<? echo $Summary; ?>"</A></H2><BR>
		<? 
		if (print_image_for_entry($row['main_image_ID'],$ID) == 1)
			{
				echo " <A href='gallery_blog_change.php?entry=$ID&oldpic={$row['main_image_ID']}'>Change picture for entry</A>";
			}
		else
			echo " <A href='gallery_blog_change.php?entry=$ID'>Add picture for entry</A>";
		?>
		
		<BR /><BR />
		<?
	}
	mysql_free_result($result);
}
?>
